// 清空身份证里面值的按钮
var approveLdentityLcon = document.getElementsByClassName("approve_identity_icon")[0];
// 选择已阅读并同意协议
var chooseBox = document.getElementById("chooseBox")
var agreementChoose = document.getElementsByClassName("agreement_choose")[0];
// 姓名输入框
var textname = document.getElementById("textname");
// 身份证号输入框
var identity = document.getElementById("identity");
// 下一步按钮
var subbtn = document.getElementById("subbtn");
// 软键盘容器
var approvePageFt = document.getElementsByClassName('approve_page_ft')[0];
var keyboards = document.getElementById("keyboard");
// 键盘上的每一个键
var lis = keyboards.getElementsByTagName("li");
// 错误弹窗模板
var approvePopup = document.getElementById("approve_popup");
var popupTextBtn = document.getElementById("popup_text_btn");
//认证成功
var approveCorrect = document.getElementById("approve_correct");
console.log(approveCorrect);


// 清空身份证号码值的按钮事件
    approveLdentityLcon.onclick = function(){
        identity.value = '';
    }
// 选中已阅读并同意协议
    var num = 1;
    var protocol = true;
    chooseBox.onclick = function() {
        num++;
        if (num % 2 == 0) {
            agreementChoose.style.display = 'none';
            protocol = false;

        } else {
            agreementChoose.style.display = 'block';
            protocol = true;
        }
    }
// 软键盘输入身份证号
    var index = 1;
    for(var i=0;i<lis.length;i++){
       lis[i].suoyin = i;
       lis[i].onclick = function(){
            index = this.suoyin;
            identity.value += lis[index].innerText;
            if(identity.value.length == 6 || identity.value.length == 15){
                identity.value = identity.value + ' ';
            }
        }
        lis[lis.length-1].onclick=function () {
            identity.value = identity.value.slice(0,identity.value.length-1);
        }
    }
// 隐藏显示软键盘
    identity.onfocus = function(){
        approvePageFt.style.bottom = '0';
        // approvePageFt.style.transition = 'all .5s';
    }
//创建一个函数，让认证成功等待着消失
    function time(){
        approveCorrect.style.display = 'none';
        approveCorrect.style.transition = 'all .5s';
    }
//验证身份证号
    subbtn.onclick = function() {
        var regName = /^[\u4E00-\u9FA5]{2,4}$/;
        var regCard = /^[1-9]{1}\d{5}\s{1}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\s\d{3}[0-9Xx]{1}$/;
        if (!regCard.test(identity.value) || !regName.test(textname.value)) {
            approvePopup.style.display = 'block';//显示错误弹框
            approvePopup.style.transition = 'all .5s'
        } else if( protocol == false){
            chooseBox.style.border = '1px solid red';
        } else {
            approvePopup.style.display = 'none'; //隐藏错误弹框
            approvePopup.style.transition = 'all .5s';
            chooseBox.style.border = '1px solid #4db5fb';
            approveCorrect.style.display = 'block'; //显示已完成
            setTimeout(time, 1000);
        }
    }
//错误提示的确认按钮
    popupTextBtn.onclick = function(){
        approvePopup.style.display = 'none';
        identity.value = '';
        textname.value = '';
    }